$(document).ready(function()
{
	$(".tabbox").css("display","none");
	var selectedTab;
	$(".tab").click(function()
	{
		var elid=$(this).attr("id");$(".tab").removeClass("tabselected");
		$("#"+elid).addClass("tabselected");
		$(".tabbox").slideUp();
		if(elid!=selectedTab)
		{
			selectedTab=elid;
			$("#"+elid+"box").slideDown();
		}
		else
		{
			selectedTab=null;
			$(".tab").removeClass("tabselected");
		}
		$("#tab").val(elid.substr(3));
	});
});

function checkinsert()
{
	var assetdepartment = document.getElementById('assetdepartment').value;
	if(assetdepartment == 'any')
	{
		alert('Asset department name can not empty');
		return false;
	}
	var serialnumber = document.getElementById('assetserialnumber').value;
	if(serialnumber == '')
	{
		alert('Serial number can not empty');
		return false;
	}
	var assetname = document.getElementById('assetname').value;
	if(assetname == '')
	{
		alert('Asset name can not empty');
		return false;
	}
	
	return true;
}

function assetinsert() 
{
	var nocache = 0;
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	document.getElementById('insert_response').innerHTML = "Just a second...";
	var assetdepartment = document.getElementById('assetdepartment').value;
	var assetserialnumber= document.getElementById('assetserialnumber').value;	
	var assetname = document.getElementById('assetname').value;
	
	nocache = Math.random();
		
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('insert_response').innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open('get', '../modules/admin/asset/functions.php?do=insert&no='+assetserialnumber+'&name='+assetname+'&dp='+assetdepartment+'&nocache='+nocache);
	xmlhttp.send();
}

function filter()
{
	var nocache = 0;
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{	
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}	

	nocache = Math.random();
	var name  = document.getElementById('searchname').value;
	var checkoutby = document.getElementById('searchcheckoutby').value;
	var status = document.getElementById('searchstatus').value;
	var department = document.getElementById('searchdepartment').value;
	
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('searchcontent').innerHTML=xmlhttp.responseText;
		}
	}
	
	xmlhttp.open('get', '../modules/admin/asset/functions.php?do=filter&name='+name+'&checkoutby='+checkoutby+'&status='+status+'&department='+department+'&nocache='+nocache);
	xmlhttp.send();
}

function asset(type,assetid) 
{
	var nocache = 0;
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{	
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}	

	nocache = Math.random();

	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(assetid).innerHTML=xmlhttp.responseText;
		}
	}
	if(type=='checkout')
	{
		xmlhttp.open('get', '../modules/admin/asset/functions.php?do=checkout&id='+assetid+'&nocache='+nocache);
		xmlhttp.send();
	}
	if(type=='checkin')
	{
		xmlhttp.open('get', '../modules/admin/asset/functions.php?do=checkin&id='+assetid+'&nocache='+nocache);
		xmlhttp.send();
	}
	if(type=='delete')
	{
		var answer = confirm("Delete?");
		if(answer)
		{
			xmlhttp.open('get', '../modules/admin/asset/functions.php?do=delete&id='+assetid+'&nocache='+nocache);
			xmlhttp.send();
		}
	}
}
